package com.cskaoyan.order.biz.handler;

import com.cskaoyan.mall.commons.exception.BizException;
import com.cskaoyan.order.biz.context.AbsTransHandlerContext;
import com.cskaoyan.order.biz.context.CreateOrderContext;
import com.cskaoyan.order.biz.context.TransHandlerContext;
import com.cskaoyan.order.constant.OrderRetCode;
import com.cskaoyan.order.dal.entitys.OrderItem;
import com.cskaoyan.order.dal.persistence.OrderItemMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class ValidateHandler extends AbstractTransHandler {

    @Autowired
    OrderItemMapper orderItemMapper;


    @Override
    public boolean isAsync() {
        return false;
    }

    @Override
    public boolean handle(TransHandlerContext context) {
        // CreateOrderContext context1 = (CreateOrderContext) context;
        // // 下单前对商品进行验证,如果商品已经下架就抛出异常提示
        // List<Long> buyProductIds = context1.getBuyProductIds();
        // for (Long buyProductId : buyProductIds) {
        //     OrderItem orderItem = orderItemMapper.selectByPrimaryKey(buyProductId);
        //     Integer status = orderItem.getStatus();
        //     if (status == 0) {
        //         throw new BizException(OrderRetCode.GOODS_TAKEN_OFF_SHELVES.getCode(), OrderRetCode.GOODS_TAKEN_OFF_SHELVES.getMessage());
        //     }
        // }
        return true;
    }
}
